<?php /*a:1:{s:67:"/www/web/siteweb/Cloud/application/index/view/User/sysGuanggao.html";i:1639722251;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台用户管理</title>
    <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<style>
    .css_red{
        color: red;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号码:</label>
                        <div class="layui-input-inline">
                            <input name="mobile_link" class="layui-input" placeholder="输入手机号码"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">用户昵称:</label>
                        <div class="layui-input-inline">
                            <input name="nickname" class="layui-input" placeholder="用户昵称"/>
                        </div>
                    </div>
                    
                    <div class="layui-inline">&emsp;
                        <button class="layui-btn icon-btn" lay-filter="userTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="userTable" lay-filter="userTable"></table>
        </div>
    </div>
</div>

<script type="text/html" id="userEditDialog">
    <form id="userEditForm" lay-filter="userEditForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">标题:</label>
            <div class="layui-input-block">
                <input name="title" placeholder="请输入标题" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">电话号码:</label>
            <div class="layui-input-block">
                <input name="mobile_link" placeholder="请输入电话号码" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">广告内容:</label>
            <div class="layui-input-block">
                <textarea name="content" height="100px" class="layui-input" rows="10" cols="20"/></textarea>
            </div>
        </div>
         <div class="layui-form-item">
                        <label class="layui-form-label">图片:</label>
                        <button type="button" class="layui-btn" id="test1">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <input type="hidden" id="image_url" name="image_url">
                        <img src="" width="100" height="200" id="phone" style="display: none">
                    </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="userEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<script type="text/html" id="sendEditDialog">
    <form id="sendEditForm" lay-filter="sendEditForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">发送者昵称:</label>
            <div class="layui-input-block">
                <input name="nickname" placeholder="请输入昵称" class="layui-input"
                       lay-verType="tips" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="sendEditSubmit" lay-submit>立即发送</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="userTbBar">
         <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="reset">刷新</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
       <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
     
</script>
<!-- 表格状态列 -->
<script type="text/html" id="userTbState">
    <input type="checkbox" lay-filter="userTbStateCk" value="{{d.id}}" lay-skin="switch"
           lay-text="已顶置|未顶置" {{d.is_top==1?'checked':''}} style="display: none;"/>
    <p style="display: none;">{{d.is_top==1?'已顶置':'未顶置'}}</p>
</script>

<script type="text/html" id="img">
    <img src="{{d.portraitUri}}" width="50" height="50">
</script>
<script type="text/html" id="img">
    {{d.role==1?'管理员':'商户'}}
</script>
<script type="text/html" id="is_reals">
    {{d.flag==1?'已审核':'待审核'}}
</script>
<!-- 表单弹窗 -->

<!-- js部分 -->
<script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/static/assets/js/common.js?v=318"></script>

<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'xmSelect','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var xmSelect = layui.xmSelect;
          var upload = layui.upload;
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#userTable',
            url: '/index/User/getsysGuanggao',
            page: true,
            toolbar: ['<p>',
                '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
                // '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
                '</p>'].join(''),
            cellMinWidth: 100,

            cols: [[
                {type: 'checkbox'},
                {type: 'numbers'},
                {field: 'nickname', title: '最后发送昵称', sort: true},
                {field: 'title', title: '广告标题', sort: true},
                {field: 'content', title: '内容', sort: true},
                {field: 'click_num', title: '点击次数',},
                {field: 'query_mobile_num', title: '号码呼叫次数',},
                {field: 'edit_num', title: '每天可编辑次数',width:180},
                {field: 'update_time', title: '最后更新时间',width:180},
                {field: 'topping_expire_time', title: '置顶到期时间',width:180},
                {
                    field: 'create_time', title: '创建时间', sort: true
                },
                {title: '操作', toolbar: '#userTbBar', align: 'center', minWidth:250}
            ]]
        });

        /* 表格搜索 */
        form.on('submit(userTbSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });

        /* 表格工具条点击事件 */
        table.on('tool(userTable)', function (obj) {
            if (obj.event === 'edit') { // 修改
                adminEditModel(obj.data);
            } else if (obj.event === 'del') { // 删除
                doDel(obj);
            } else if (obj.event === 'reset') { // 重置密码
                doFail(obj.data);
            } else if(obj.event === 'reUploadimg1'){ // 重新上传身份证

            }else if(obj.event === 'reUploadimg2'){ // 重新上传营业执照
                doYingyezhizhao(obj);
            }
        });
         $(document).on('change', '#fenlei', function(data) {

            var fenleival = $("#fenlei").val();
            $("#fenlei2").empty();
            $.post('/indexx.php?c=order&m=geterjiFenlei', {
                felieid:fenleival
            }, function (res) {
                var alltype = res.data;
                $("#fenlei2").append('<option value="">选择</option>');
                alltype.forEach(function(a,c){
                    var html = '<option value="'+a.id+'">'+a.name+'</option>';
                    $("#fenlei2").append(html);
                })
            }, 'json');
        });
        /* 表格头工具栏点击事件 */
        table.on('toolbar(userTable)', function (obj) {
            if (obj.event === 'add') { // 添加
                adminEditModel();
            } else if (obj.event === 'del') { // 删除
                var checkRows = table.checkStatus('userTable');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.userId;
                });
                doDel({ids: ids});
            }
        });
         /* 修改用户状态 */
        form.on('switch(userTbStateCk)', function (obj) {
            var loadindexx = layer.load(2);
            $.post('/index/User/changeguanggaoState', {
                userId: obj.elem.value,
                state: obj.elem.checked ? 1 : 0
            }, function (res) {

                layer.close(loadindexx);
                if (res.code === 1) {
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.msg, {icon: 2});
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'json');
        });
        /* 显示表单弹窗 */
        function adminEditModel(mData) {

            admin.open({
                type: 1,
                area: ['980px','500px'],
                title: (mData ? '查看' : '查看') + '用户',
                content: $('#userEditDialog').html(),
                success: function (layero, dindexx) {
                    // 表单提交事件
                    form.val('userEditForm', mData);
                    if(mData){
                        $("#phone").show();
                        $("#phone").attr('src',mData.image_url);
                    }
                    form.on('submit(userEditSubmit)', function (data) {
                        var loadindexx = layer.load(2);
                        $.post( mData ? '/index/User/editSysGuanggao' : '/index/User/AddSysGuanggao',data.field, function (res) {  // 实际项目这里url可以是mData?'user/update':'user/add'
                            layer.close(loadindexx);
                            if (res.code === 1) {
                                layer.close(dindexx);
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                        return false;
                    });
                     var uploadInst = upload.render({
                        elem: '#test1' //绑定元素
                        ,url: '/index/User/upload' //上传接口
                        ,done: function(res){
                            //上传完毕回调
                           console.log(res);
                            $("#phone").show();
                            $("#phone").attr('src', "/"+res.msg);
                            $("#test1").hide();
                            $("#image_url").val(res.msg);
                        }
                        ,error: function(){
                            //请求异常回调
                        }
                    });
                }
            });
        }
        /* 审核 */
        function doDel(obj) {
            layer.confirm('确定删除吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                var loadindexx = layer.load(2);
                $.post('/index/User/delsysGuanggao', {
                    id: obj.data.id,
                }, function (res) {
                    layer.close(loadindexx);
                    if (res.code === 1) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }

        function doFail(obj) {
            console.log(obj);
            layer.confirm('确定发送吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                var loadindexx = layer.load(2);
                
                $.post('/index/User/sendGuanggao', {
                   id: obj.id,
                   nickname:obj.title
                }, function (res) {
                    layer.close(loadindexx);
                    if (res.code === 1) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
            
        }
        function doYingyezhizhao(obj){
            layer.confirm('确定用户重新上传营业执照吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                var loadindexx = layer.load(2);

                $.post('/index/Auth/shenheFailYingye', {
                    id: obj.data.id,

                }, function (res) {
                    layer.close(loadindexx);
                    if (res.code === 1) {
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'json');
            });
        }

    });
</script>
</body>
</html>
